function sqrt(num) {
    let right = num;
    let left = 0;
    let ret = num / 2;
    while (Math.abs(ret * ret - num) > 0.001) {
        // 二分法得出来的ret平方大于num，
        // 那么right就向前靠拢
        // 再用二分法重新计算ret的值
        if (ret * ret - num > 0) {
            right = ret;
            ret = ret - (right - left) / 2;
        } else {
            left = ret;
            ret = ret + (right - left) / 2;
        }
    }
    console.log(ret);
}
sqrt(9);
